//
//  StatusBarManager.swift
//  MacScreenshot
//
//  Created by mac on 2024/11/27.
//

// 新建文件 StatusBarManager.swift
import Cocoa

class StatusBarManager {
    private var statusItem: NSStatusItem
    private var menu: NSMenu
    
    init() {
        statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
        menu = NSMenu()
        
        if let button = statusItem.button {
            button.image = NSImage(systemSymbolName: "camera", accessibilityDescription: "Screenshot")
        }
        
        setupMenu()
        statusItem.menu = menu
    }
    
    private func setupMenu() {
        // 添加截图菜单项
        let screenshotItem = NSMenuItem(
            title: "截图",
            action: #selector(AppDelegate.takeScreenshot),
            keyEquivalent: "a"
        )
        screenshotItem.keyEquivalentModifierMask = [NSEvent.ModifierFlags.command, NSEvent.ModifierFlags.shift]
        screenshotItem.target = NSApp.delegate as? AppDelegate
        menu.addItem(screenshotItem)
        
        // 添加设置菜单项
        let settingsItem = NSMenuItem(
            title: "设置",
            action: #selector(AppDelegate.showSettings),
            keyEquivalent: ","
        )
        settingsItem.target = NSApp.delegate as? AppDelegate
        menu.addItem(settingsItem)
        
        // 添加分隔线
        menu.addItem(NSMenuItem.separator())
        
        // 添加退出菜单项
        let quitItem = NSMenuItem(
            title: "退出",
            action: #selector(AppDelegate.quit),
            keyEquivalent: "q"
        )
        quitItem.target = NSApp.delegate as? AppDelegate
        menu.addItem(quitItem)
    }
}
